package com.zhousb.deviceManager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhousb.deviceManager.mapper.OrderBackMapper;
import com.zhousb.deviceManager.model.entity.KtOrderBack;
import com.zhousb.deviceManager.model.enums.OrderStatusEnum;
import com.zhousb.deviceManager.model.so.OrderSO;
import com.zhousb.deviceManager.service.OrderBackService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @author ZhouShenBin
 * @date 2024/6/27 19:38
 * @description
 */
@Service
public class OrderBackServiceImpl implements OrderBackService {

    @Resource
    private OrderBackMapper orderBackMapper;
    @Override
    public Page page(Page<KtOrderBack> page, OrderSO so) {
        LambdaQueryWrapper<KtOrderBack> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(StringUtils.hasText(so.getClientName()), KtOrderBack::getClientName, so.getClientName())
                .eq(!Objects.equals(so.getOrderStatus(), OrderStatusEnum.DEFAULT.getCode()), KtOrderBack::getOrderStatus, so.getOrderStatus())
                .eq(StringUtils.hasText(so.getOrderCode()), KtOrderBack::getOrderCode, so.getOrderCode());
        Page<KtOrderBack> data = orderBackMapper.selectPage(page, queryWrapper);
        return data;
    }
}
